home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 3 / ct-rom iiib.zip / ct-rom iiib / WINDOWS / UTILITY / DESKTOP / CB200 / C-CALEND.C_ / C-CALEND.C
C/C++ Source or Header  |  1993-09-01  |  9KB  |  348 lines

  1. // === calend.c ===
  2.  
  3. // Calendar Add-In for the clySmic Icon Bar. (C) 1992 by clySmic Software.
  4. // All Rights Reserved.
  5.  
  6. #include <windows.h>
  7. #include <stdio.h>
  8. #include <dos.h>
  9.  
  10. #include "add-in.h"
  11. #include "homedir.c"
  12.  
  13. HANDLE  hInstance;                   // DLL's instance handle
  14. BOOL ShowDOW = TRUE;
  15. struct dosdate_t Today;
  16. char IWDate[80],INIFile[80];
  17. BOOL USDateFormat;
  18.  
  19. #define CBVer "2.00"
  20.  
  21. /*-------------------------------------------------------------------*/
  22.  
  23. // LibMain
  24.  
  25. int WINAPI LibMain(HANDLE hLibInst, WORD wDataSeg,
  26.                        WORD cbHeapSize, LPSTR lpszCmdLine)
  27. {
  28.   hInstance = hLibInst;
  29.   return 1;
  30.  
  31. } /*LibMain*/
  32.  
  33. /*-------------------------------------------------------------------*/
  34.  
  35. // Windows Exit Procedure
  36.  
  37. int WINAPI WEP(int bSystemExit)
  38. {
  39.   return 1;
  40.  
  41. } /*WEP*/
  42.  
  43. /*-------------------------------------------------------------------*/
  44.  
  45. // Utility Function to center text
  46.  
  47. int CenterTx(HDC DC, char *Tx, RECT Rect)
  48.  
  49. {
  50.   int Width,WinX,StrtX;
  51.  
  52.   // Ask Windows for the total pixel length of the string & calc starting X
  53.   Width = LOWORD(GetTextExtent(DC,Tx,strlen(Tx)));
  54.  
  55.   // Get total x width of window - don"t add 1!
  56.   WinX = (Rect.right - Rect.left);
  57.  
  58.   // Calculate centered starting posn
  59.   StrtX = ((WinX - Width) / 2) + Rect.left;
  60.  
  61.   return StrtX;
  62.  
  63. } /*CenterTx*/
  64.  
  65. /*-------------------------------------------------------------------*/
  66.  
  67. VOID FormIWDate()
  68.  
  69. {
  70.   char *MonthName[12] =
  71.     {"January","February","March","April","May","June",
  72.      "July","August","September","October","November","December"};
  73.  
  74.   char *Days[7] =
  75.      {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
  76.  
  77.   _dos_getdate(&Today);
  78.  
  79.   if (USDateFormat)
  80.     {
  81.       // US date fmt
  82.       sprintf(IWDate,"C: %s, %s %d, %d",Days[Today.dayofweek],MonthName[Today.month],
  83.                                         Today.day,Today.year);
  84.     }
  85.   else
  86.     {
  87.       // European date fmt 
  88.       sprintf(IWDate,"C: %s, %d %s %d",Days[Today.dayofweek],Today.day,
  89.                                        MonthName[Today.month],Today.year);
  90.     }
  91. } /*FormIWDate*/
  92.  
  93. /*-------------------------------------------------------------------*/
  94.  
  95. // Perform Add-In's initialization
  96.  
  97. InitResult WINAPI AddInInit(char far *CurVer)
  98.  
  99. {
  100.   // Version check
  101.   if (strcmp(CurVer,CBVer) != 0)
  102.     return InitNotOk;
  103.  
  104.   // Point at our INI file, which is in our home dir
  105.   HomeDir(hInstance,INIFile);
  106.   strcat(INIFile,"C-CALEND.INI");
  107.  
  108.   // Flush INI file so we can edit it
  109.   WritePrivateProfileString(NULL,NULL,NULL,INIFile);
  110.  
  111.   // Get display mode
  112.   USDateFormat = GetPrivateProfileInt("Settings",
  113.                                       "USDateFormat",
  114.                                       0,
  115.                                       INIFile);
  116.  
  117.   return InitOk;
  118. } /*AddInInit*/
  119.  
  120. /*-------------------------------------------------------------------*/
  121.  
  122. // Paint on the button (Clysbar does the background)
  123.  
  124. VOID WINAPI AddInPaint(HWND Wnd, HDC DC, BOOLEAN Pressed)
  125.  
  126. {
  127.   char *MonthName[12] =
  128.     {"JAN","FEB","MAR","APR","MAY","JUN",
  129.      "JUL","AUG","SEP","OCT","NOV","DEC"};
  130.  
  131.   char *Days[7] =
  132.      {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  133.  
  134.   RECT Rect,ShadRect;
  135.   HFONT NumFont,OldFont,SmlFont;
  136.   char Tx[128];
  137.   char StrYr[5],StrDay[5];       // or 4?
  138.   int StrtX,StrtY;
  139.   HICON TheIcon;
  140.  
  141.   GetClientRect(Wnd,&Rect);
  142.  
  143.   // Calc location of icon 
  144.   StrtX = ((Rect.right - Rect.left) - GetSystemMetrics(SM_CXICON)) / 2;
  145.   StrtY = ((Rect.bottom - Rect.top) - GetSystemMetrics(SM_CYICON)) / 2;
  146.  
  147.   // Draw turning page if pressed
  148.   if (Pressed)
  149.     {
  150.       TheIcon = LoadIcon(hInstance,"turning");
  151.       DrawIcon(DC,StrtX+1,StrtY+1,TheIcon);
  152.  
  153.       return;
  154.     }
  155.  
  156.   // Draw "page" icon
  157.   TheIcon = LoadIcon(hInstance,"calend");
  158.   DrawIcon(DC,StrtX,StrtY,TheIcon);
  159.  
  160.   // Get date info
  161.   _dos_getdate(&Today);
  162.  
  163.   itoa(Today.day,StrDay,10);
  164.   itoa(Today.year,StrYr,10);
  165.  
  166.   // Lop off 1st two year digits
  167.   //StrYr[0] = StrYr[2];
  168.   //StrYr[1] = StrYr[3];
  169.   //StrYr[2] = NULL;
  170.  
  171.   // Create a small font for the month/day name/year
  172.   SmlFont =
  173.   CreateFont(9,             // Height
  174.              0,0,0,         // Width, left 2 right, normal orientation
  175.              400,           // Weight
  176.              0,0,0,         // Italic, underlined, or strikeout
  177.              0,             // ANSI char set
  178.              0,             // Reserved precision field
  179.              0,             // Default clipping
  180.              PROOF_QUALITY, // Quality
  181.              FF_ROMAN | VARIABLE_PITCH,
  182.              "Small Fonts");
  183.  
  184.   // Create large font for the day number
  185.   NumFont =
  186.   CreateFont(17,            // Height
  187.              0,0,0,         // Width, left 2 right, normal orientation
  188.              700,           // Weight
  189.              0,0,0,         // Italic, underlined, or strikeout
  190.              0,             // ANSI char set
  191.              0,             // Reserved precision field
  192.              0,             // Default clipping
  193.              PROOF_QUALITY, // Quality
  194.              FF_ROMAN | VARIABLE_PITCH,
  195.              "Times New Roman");
  196.  
  197.   // Setup for day number
  198.   OldFont = SelectObject(DC,NumFont);
  199.   SetBkMode(DC,TRANSPARENT);
  200.  
  201.   // Draw lg day number's shadow
  202.   SetTextColor(DC,RGB(128,128,128));
  203.   ShadRect = Rect;
  204.   OffsetRect(&ShadRect,1,1);
  205.   DrawText(DC,StrDay,strlen(StrDay),&ShadRect,
  206.            DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  207.  
  208.   // Draw lg day number
  209.   SetTextColor(DC,RGB(0,0,0));
  210.   DrawText(DC,StrDay,strlen(StrDay),&Rect,
  211.            DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  212.  
  213.   // Setup for other info
  214.   SelectObject(DC,SmlFont);
  215.  
  216.   // Draw month name
  217.   SetTextColor(DC,RGB(255,0,0));
  218.   strcpy(Tx,MonthName[Today.month-1]);
  219.   TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 1,Tx,strlen(Tx));
  220.  
  221.   // either year or DOY
  222.   if (ShowDOW)
  223.     {
  224.       // Display day of week
  225.       strcpy(Tx,Days[Today.dayofweek]);
  226.       SetTextColor(DC,RGB(0,0,128));
  227.       TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 22,Tx,strlen(Tx));
  228.     }
  229.   else
  230.     {
  231.       // Display year
  232.       strcpy(Tx,StrYr);
  233.       SetTextColor(DC,RGB(128,0,128));
  234.       TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 22,Tx,strlen(Tx));
  235.     }
  236.  
  237.   // Clean up
  238.   SelectObject(DC,OldFont);
  239.   DeleteObject(SmlFont);
  240.   DeleteObject(NumFont);
  241.  
  242. } /*AddInPaint*/
  243.  
  244. /*-------------------------------------------------------------------*/
  245.  
  246. // Tell Clysbar what kind of timer we need
  247.  
  248. int WINAPI AddInTimerNeeded()
  249.  
  250. {
  251.   return ait_Slow;
  252. } /*AddInTimerNeeded*/
  253.  
  254. /*-------------------------------------------------------------------*/
  255.  
  256. // Proc called when timer expires, perform timed duties
  257.  
  258. VOID WINAPI AddInTimerTick(HWND Wnd, HDC DC)
  259.  
  260. {
  261.   struct dosdate_t TstDate;
  262.  
  263.   // Check for a date change
  264.   _dos_getdate(&TstDate);
  265.  
  266.   // If different date, repaint window
  267.   if (TstDate.day != Today.day)
  268.     AddInPaint(Wnd,DC,FALSE);
  269.  
  270. } /*AddInTimerTick*/
  271.  
  272. /*-------------------------------------------------------------------*/
  273.  
  274. // Proc called when button pressed and released (used for toggling states)
  275.  
  276. VOID WINAPI AddInPressed(HWND Wnd, HDC DC)
  277.  
  278. {
  279.   // Toggle the "show day-of-week" indicator when button pressed
  280.   ShowDOW = !ShowDOW;
  281.  
  282.   AddInPaint(Wnd,DC,FALSE);
  283. } /*AddInPressed*/
  284.  
  285. /*-------------------------------------------------------------------*/
  286.  
  287. // Exit processing for Add-In
  288.  
  289. VOID WINAPI AddInExit()
  290.  
  291. {
  292. } /*AddInExit*/
  293.  
  294. /*-------------------------------------------------------------------*/
  295.  
  296. // Clysbar queries Add-In about itself for About box
  297.  
  298. VOID WINAPI AddInAbout(char far *Str1, char far *Str2,
  299.                            HICON far *TheIcon,
  300.                            COLORREF far *TitleCol,
  301.                            COLORREF far *TxCol,
  302.                            COLORREF far *BkCol)
  303.  
  304. {
  305.   strcpy(Str1,"C-Calend V2.00");
  306.   strcpy(Str2,"'C' Code Demo Example\n⌐ 1993 by clySmic Software.\nAll Rights Reserved.");
  307.  
  308.   *TheIcon = LoadIcon(hInstance,"about");
  309.   *TitleCol = RGB(255,255,255);
  310.   *TxCol = RGB(192,192,192);
  311.   *BkCol = RGB(255,0,0);
  312. } /*AddInAbout*/
  313.  
  314. /*-------------------------------------------------------------------*/
  315.  
  316.  
  317. // Clysbar queries Add-In whether it'll accept d'n'd
  318.  
  319. BOOL WINAPI AddInAcceptDrops()
  320.  
  321. {
  322.   return FALSE;
  323. } /*AddInAcceptDrops*/
  324.  
  325. /*-------------------------------------------------------------------*/
  326.  
  327.  
  328. // Clysbar informs Add-In of a d'n'd drop
  329.  
  330. VOID WINAPI AddInDrop(HANDLE hDrop)
  331.  
  332. {
  333. } /*AddInDrop*/
  334.  
  335. /*-------------------------------------------------------------------*/
  336.  
  337. // Clysbar queries Add-In for Info Window text
  338.  
  339. // Return a zero-length string if you don't want to chg the text
  340.  
  341. VOID WINAPI AddInGetInfoWinTx(char *Tx)
  342.  
  343. {
  344.   FormIWDate();
  345.  
  346.   strcpy(Tx,IWDate);
  347. } /*AddInGetInfoWinTx*/
  348.